import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { SettingsService, TitleService } from '@core';
import { filter } from 'rxjs/operators';
import { UserAuthService } from '@core/services/user-auth.service';
import {AnalysisService} from "./routes/analysis/analysis.service";

@Component({
  selector: 'apes-root',
  template: `<router-outlet></router-outlet>`,
})
export class AppComponent implements OnInit {
  @HostBinding('class.layout-fixed')
  get isFixed() {
    return this.settings.layout.fixed;
  }
  @HostBinding('class.layout-boxed')
  get isBoxed() {
    return this.settings.layout.boxed;
  }
  @HostBinding('class.aside-collapsed')
  get isCollapsed() {
    return this.settings.layout.collapsed;
  }

  constructor(
    private settings: SettingsService,
    private router: Router,
    private titleSrv: TitleService,
    private userAuthService: UserAuthService
  ) {}

  ngOnInit() {
    let platform = this.userAuthService.getUserInfoObj() ? this.userAuthService.getUserInfoObj().platform : '';
    let item = window.location.hash;
    if (this.isBool(item, 'headquarters') || platform == 'zt') {
      this.titleSrv.suffix = '总部后台';
      this.titleSrv.default = '总部后台';
    }else if (this.isBool(item, 'empower') || platform == 'fn' || platform == 'gys') {
      this.titleSrv.suffix = '集群车宝赋能平台';
      this.titleSrv.default = '集群车宝赋能平台';
    }else {
      this.titleSrv.suffix = '集群车宝赋能平台';
    }

    this.router.events
      .pipe(filter(evt => evt instanceof NavigationEnd))
      .subscribe(() => this.titleSrv.setTitle());
  }

  isBool(str, substr) {
    return str.indexOf(substr) >= 0;
  }

}
